package com.ikangtai.shecare.common.baseView.recordButtonView;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.RecordFragmentCommonList;
import com.ikangtai.shecare.main.RecordFragment;

/**
 * Created by Administrator on 2016/1/20.
 */
public class RecordSelectMensesButton extends RecordSelectButton{

    private Context context;
    public static final int RECORD_MENSES_SELECT_WHITE_BACKGROUND_COLOR = 0;
    public static final int RECORD_MENSES_SELECT_BLUE_BACKGROUND_COLOR = 1;
    public static final String RecordSelectMensesButtonType="MENSES";

    public RecordSelectMensesButton(Context context){
        super(context);
        this.context=context;
        setType(RecordSelectMensesButtonType);
    }
    public RecordSelectMensesButton(Context context, AttributeSet attrs){
        super(context,attrs);
        this.context=context;
       this.backgroundColor = RECORD_MENSES_SELECT_WHITE_BACKGROUND_COLOR;
    }

    @Override
    public void setColor(int backGroundColor) {
        super.setColor(backGroundColor);
    }

    @Override
    public void clickAction(View view) {
        RecordSelectMensesButton recordMensesYesBtn;
        RecordSelectMensesButton recordMensesNoBtn;
       if(null!=view){
           recordMensesYesBtn=(RecordSelectMensesButton)view.findViewById(R.id.record_menses_btn_yes);
           recordMensesNoBtn=(RecordSelectMensesButton)view.findViewById(R.id.record_menses_btn_no);

        if(backgroundColor == RECORD_MENSES_SELECT_WHITE_BACKGROUND_COLOR||backgroundColor == RECORD_MENSES_SELECT_BLUE_BACKGROUND_COLOR){
            backgroundColor = RECORD_MENSES_SELECT_BLUE_BACKGROUND_COLOR;
            if(this.getId()==recordMensesYesBtn.getId()){
                RecordFragment.mensesBlood = 1;
                this.setBackground(getResources().getDrawable(R.drawable.record_menses_button_pressed));
                this.setTextColor(Color.WHITE);
                recordMensesNoBtn.setBackground(getResources().getDrawable(R.drawable.record_menses_button_default));
                recordMensesNoBtn.setTextColor(getResources().getColor(R.color.yjq_color));
            }

            if(this.getId()==recordMensesNoBtn.getId()){
                RecordFragment.mensesBlood = 0;
                this.setTextColor(Color.WHITE);
                this.setBackground(getResources().getDrawable(R.drawable.record_menses_button_pressed));
                recordMensesYesBtn.setBackground(getResources().getDrawable(R.drawable.record_menses_button_default));
                recordMensesYesBtn.setTextColor(getResources().getColor(R.color.yjq_color));
            }

            for(int i=0;i< RecordFragmentCommonList.mensesDysmenorrheaBtn.length;i++){
                if(this.getId() == RecordFragmentCommonList.mensesDysmenorrheaBtn[i]){
                    RecordFragment.mensesDysmenorrhea = i + 1;
                    this.setBackground(getResources().getDrawable(R.drawable.record_menses_button_pressed));
                    this.setTextColor(Color.WHITE);
                    for(int j=0;j< RecordFragmentCommonList.mensesDysmenorrheaBtn.length;j++){
                        if(RecordFragmentCommonList.mensesDysmenorrheaBtn[i] != RecordFragmentCommonList.mensesDysmenorrheaBtn[j]){
                            RecordSelectMensesButton button = (RecordSelectMensesButton)view.findViewById(RecordFragmentCommonList.mensesDysmenorrheaBtn[j]);
                            button.setColor(RECORD_MENSES_SELECT_WHITE_BACKGROUND_COLOR);
                            button.setBackground(getResources().getDrawable(R.drawable.record_menses_button_default));
                            button.setTextColor(getResources().getColor(R.color.yjq_color));
                        }
                    }
                }
            }

            for(int i=0;i< RecordFragmentCommonList.mensesColorBtn.length;i++){
                if(this.getId() == RecordFragmentCommonList.mensesColorBtn[i]){
                    RecordFragment.mensesColor = i+1;
                    this.setBackground(getResources().getDrawable(RecordFragmentCommonList.mensesColorDrawableSelected[i]));
                    for(int j=0;j< RecordFragmentCommonList.mensesColorBtn.length;j++){
                        if(RecordFragmentCommonList.mensesColorBtn[i] != RecordFragmentCommonList.mensesColorBtn[j]){
                            RecordSelectMensesButton button = (RecordSelectMensesButton)view.findViewById(RecordFragmentCommonList.mensesColorBtn[j]);
                            button.setBackground(getResources().getDrawable(RecordFragmentCommonList.mensesColorDrawable[j]));
                            button.setColor(RECORD_MENSES_SELECT_WHITE_BACKGROUND_COLOR);

                        }
                    }
                }
            }

            for(int i=0;i< RecordFragmentCommonList.mensesFlowBtn.length;i++){
                if(this.getId() == RecordFragmentCommonList.mensesFlowBtn[i]){
                    RecordFragment.mensesFlow = i + 1;
                    this.setBackground(getResources().getDrawable(R.drawable.record_menses_flow_button_pressed));
                    for(int j=0;j< RecordFragmentCommonList.mensesFlowBtn.length;j++){
                        if(RecordFragmentCommonList.mensesFlowBtn[i] != RecordFragmentCommonList.mensesFlowBtn[j]){
                            RecordSelectMensesButton button = (RecordSelectMensesButton)view.findViewById(RecordFragmentCommonList.mensesFlowBtn[j]);
                            if(j<i){
                                button.setBackground(getResources().getDrawable(R.drawable.record_menses_flow_button_pressed));
                                button.setColor(RECORD_MENSES_SELECT_BLUE_BACKGROUND_COLOR);
                            }
                            else {
                                button.setBackground(getResources().getDrawable(R.drawable.record_menses_flow_button_default));
                                button.setColor(RECORD_MENSES_SELECT_WHITE_BACKGROUND_COLOR);
                            }
                        }
                    }
                }
            }
        }
       }
    }

}
